package Task04_1;

//作业1

/*编写一个员工类   (1)属性: 姓名,年龄       如果年龄小于18龄大于150抛出年龄异常       如果姓名为null或者""抛出空异常*/
public class Staff {
    private String name;
    private int age;

    public Staff() {
    }
    public Staff(String name, int age) throws AgeException {
        if (age > 18 && age <150) {
            setAge(age);
        } else
            throw new AgeException("年龄不合理");
        if (name == null || "".equals(name)){
            throw new NullPointerException("空指针异常");
        }
        else
            setName(name);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name == null || "".equals(name)){
            throw new NullPointerException("空指针异常");
        }
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws AgeException {
        if (age < 18 || age > 150){
           throw  new AgeException("年龄不合理");
        }else
            this.age = age;
    }
    @Override
    public String toString() {
        return "Staff{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
